﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;


namespace 人事工资管理系统
{
    public partial class frmOperator : Form
    {
        public frmOperator()
        {
            InitializeComponent();
        }
        PMSClass.DBOperate operate = new PMSClass.DBOperate();
        SqlConnection conn = PMSClass.DBConnection.MyConnection();
        public string Uid;
        private void frmOperator_Load(object sender, EventArgs e)
        {
            string str =
            "select ID as '编码',UserName as '用户名',UserPWd as '密码',power as '权限',LoginTime as'登陆时间'from tb_User";
            operate.BindDataGridView(dgvEmployee, str);
            dgvEmployee.Columns[0].Width = 40;
            dgvEmployee.Columns[1].Width = 80;
        }

        

        private void toolStripLabel1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text == "" || textBox2.Text == "" || comboBox1.Text == "")
            {
                MessageBox.Show("请将信息填写完整", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            else
            {
                string sql = "select count(*)from tb_User where UserName='" + textBox1.Text + "'";
                int i = operate.HumanNum(sql);
                if (i > 0)
                {
                    MessageBox.Show("用户已经存在!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
                else
                {
                    string str = "insert into tb_User(UserName,UserPwd,power,LoginTime)values('" + textBox1.Text.ToString() + "','" + textBox2.Text.ToString() + "','" + comboBox1.Text.ToString() + "','" +DateTime.Now.ToString() +"')";
                    int num = operate.OperateData(str);
                    if (num > 0)
                    {
                        MessageBox.Show("添加成功！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                   
                }
            }
        }

        private void toolStripLabel2_Click(object sender, EventArgs e)
        {
            if (dgvEmployee.SelectedCells.Count == 0)
            {
                MessageBox.Show("请选择要删除的信息", "警告", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            else
            {
                string id = dgvEmployee.SelectedCells[0].Value.ToString();
                string sql = "delete from tb_User where ID='" + id + "'";
                operate.OperateData(sql);
                MessageBox.Show("删除成功", "警告", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
        }
    }

